/*
 * XX公司源代码，版权归XX公司所有。
 * 
 * 项目名称 : it-ogt-kq-common
 * 创建日期 : 2023年8月15日
 * 修改历史 : 
 *     1. [2023年8月15日]创建文件 by huangwu
 */
package com.hyt.it.ogt.kq.common.utils;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
/**
 * LocalDateTime 转换类
 * @author huangwu
 */
public class LocalDateTimeConverter implements Converter<LocalDateTime> {

    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public Class supportJavaTypeKey() {
        return LocalDateTime.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public LocalDateTime convertToJavaData(ReadCellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String dateString = cellData.getStringValue();
        return LocalDateTime.parse(dateString, FORMATTER);
    }

    @Override
    public WriteCellData<?> convertToExcelData(LocalDateTime localDateTime, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String dateString = localDateTime.format(FORMATTER);
        return new WriteCellData(dateString);
    }
}
